from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
from direct.distributed.PyDatagram import PyDatagram
from direct.distributed.PyDatagramIterator import PyDatagramIterator

class Test(ShowBase):

    port_address=9099  # same for client and server
 
 # a valid server URL. You can also use a DNS name
 # if the server has one, such as "localhost" or "panda3d.org"
    ip_address="127.0.0.1"
 
 # how long until we give up trying to reach the server?
    timeout_in_miliseconds=3000  # 3 seconds
 

    cManager = QueuedConnectionManager()
    cReader = QueuedConnectionReader(cManager, 0)
    cWriter = ConnectionWriter(cManager,0)

    port_address=9099 #No-other TCP/IP services are using this port
    backlog=1000 #If we ignore 1,000 connection attempts, something is wrong!

    def __init__(self):
        ShowBase.__init__(self)
        
        self.myConnection=self.cManager.openTCPClientConnection( self.ip_address,self.port_address,self.backlog)
        if self.myConnection:
            self.cReader.addConnection(self.myConnection)  # receive messages from server
            #self.cWriter.addConnection(self.myConnection)
            datagram = PyDatagram()
            datagram.addString("Hello world!")
            self.cWriter.send(datagram, self.myConnection)

obj = Test()
obj.run()
